//
//  ActPaymentSelectionViewController.m
//  ActSistant
//
//  Created by Loan Dinh on 2/27/13.
 //

#import "ActPaymentSelectionViewController.h"
#import "ActSettingViewController.h"
#import "NavigationView.h"

#define kTextColorCell [UIColor darkGrayColor]
#pragma mark - ActPaymentSelectionCellWrapper
@class ActPaymentSelectionCellWrapper;
@interface ActPaymentSelectionCellWrapper : NSObject
@property (nonatomic, retain) NSString *cellAddress;
@property (nonatomic, retain) NSString *cellPhoneNumber;
-(id)initWithAddress:(NSString*)address andPhoneNumber:(NSString*)phoneNumber;
@end
@implementation ActPaymentSelectionCellWrapper
@synthesize cellAddress, cellPhoneNumber;
-(id)initWithAddress:(NSString *)address andPhoneNumber:(NSString *)phoneNumber{
    self = [super init];
    if(self){
        cellAddress = address;
        cellPhoneNumber = phoneNumber;
    }
    return self;
}
-(void)dealloc{
    [cellAddress release];
    [cellPhoneNumber release];
    [super dealloc];
}
@end
#pragma mark - ActPaymentSelectionViewController
@interface ActPaymentSelectionViewController ()
{
    ActPaymentSelectionType _type;
}
@end

@implementation ActPaymentSelectionViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(id)initWithPaymentSelectionType:(ActPaymentSelectionType)type{
    self = [super initWithNibName:@"ActPaymentSelectionViewController" bundle:nil];
    if(self) {
        _type = type;
    }
    return self;
}
-(void)loadData{
    if(!_data){
        _data = [[NSMutableArray array] retain];
    }
    [_data removeAllObjects];
    switch (_type) {
        case ActPaymentSelectionTypeCAPS:
        {
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"10600 Virginia Ave. Culver City, CA 90232" andPhoneNumber:@"(310) 845-9187"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"400 Skokie Blvd. Suite 460. Norbrook, IL 60062" andPhoneNumber:@"(847) 480-9752"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"588 Broadway, Suite 608, New York, NY 10012" andPhoneNumber:@"(212) 925-1415"]];
        }
            break;
        case ActPaymentSelectionTypeCentreCasting:
        {
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"2835 North Naomi Street, Burbank, CA" andPhoneNumber:@"(818) 955-6000"]];

        
        }
            break;
        case ActPaymentSelectionTypeEntertainment:
        {
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"2835 North Naomi Street, Burbank, CA" andPhoneNumber:@"(818) 955-6000"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"571 Park Avenue, Hoover, AL" andPhoneNumber:@"(818) 955-6216"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"1200 High Ride Road, Stamford, CT" andPhoneNumber:@"(203) 291-9399"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"2000 Universal Studios Plaza, Orlando, FL" andPhoneNumber:@"(407) 351-4037"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"2835 Nord Naomi Street, Burbank, CA" andPhoneNumber:@"(818) 955-6000"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"ScreenGems, 175 Lakewood Way, #316, Atlanta, GA" andPhoneNumber:@"(404) 276-2502"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"3445 N. Causeway Blvd, Suite 704 Metairie, LA70002" andPhoneNumber:@"(504) 277-2240"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"875 6th Avernue, 15th Floor New York, NY" andPhoneNumber:@"(646) 473-9000"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"Screen Gems, 1223 23rd Street North Wilmington, NC" andPhoneNumber:@"(910) 343-3535"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"109 Dewalt, Suite 109, Pitsburg, PA" andPhoneNumber:@"(412) 956-7325"]];
            [_data addObject:[[ActPaymentSelectionCellWrapper alloc] initWithAddress:@"Sun Center Studio 63 Concord Road, Aston, PA" andPhoneNumber:@"(610) 717-4221"]];
        
        }
            break;
        default:
            break;
    }
}
-(void)dealloc{
    [_tableView release];
    [_data release];
    [_navigationView release];
    [super dealloc];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self.navigationView.btnBack addTarget:self action:@selector(doBackbarButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationView.btnRight1 addTarget:self action:@selector(doSetting:) forControlEvents:UIControlEventTouchUpInside];
    [self loadData];
    _tableView.tableHeaderView = [self createTableHeader];
    _tableView.separatorColor = [UIColor lightGrayColor];
}

- (void)doSetting:(id)sender{
    ActSettingViewController *controller = [[ActSettingViewController alloc] initWithNibName:@"ActSettingViewController" bundle:nil];
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}
-(void)doBackbarButton:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - table view
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
        [cell.textLabel setFont:UIFontVerdana(10)];
        [cell.detailTextLabel  setFont:UIFontVerdana(8)];
        [cell.textLabel setTextColor:kTextColorCell];
//        [cell setBackgroundView:nil];
    }
    if(indexPath.row < _data.count){
        ActPaymentSelectionCellWrapper *cellData = [_data objectAtIndex:indexPath.row];
        cell.textLabel.text = cellData.cellAddress;
        cell.detailTextLabel.text = cellData.cellPhoneNumber;
        [cell setBackgroundColor:[UIColor clearColor]];
    }
    return cell;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UILabel *label = [[UILabel alloc]  initWithFrame:CGRectMake(10, 0, 300, 40)];
    [label setText:@"Select location:"];
    [label setFont:UIFontVerdana(16)];
    [label setTextColor:kTextColorCell];
    [label setBackgroundColor:[UIColor clearColor]];
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)] autorelease];
    [headerView addSubview:label];
    [label release];
    return headerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(_data){
        return [_data count];
    }
    return 1;
}
-(UIView *)createTableHeader{
    UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 110)] autorelease];
    UIImageView* labelView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320,45)];
    [labelView setImage:[UIImage imageNamed:@"paymentbackground"]];
    [view addSubview:labelView];
    [labelView release];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 5, 250,35)];
    [label setTextColor:[UIColor whiteColor]];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setText:@"Select Payroll"];
    [label setFont:UIFontVerdana(25)];
    [view addSubview:label];
    [label release];
    
    UITableViewCell *cell  = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    
    [cell setFrame:CGRectMake(0,60, 320, 45)];
    [cell.textLabel setBackgroundColor:[UIColor clearColor]];
    [cell.textLabel setTextColor:kTextColorCell];
    [cell.textLabel setFont:UIFontVerdana(20)];
    [cell.detailTextLabel setFont:UIFontVerdana(14)];
    switch (_type) {
        case ActPaymentSelectionTypeCAPS:
            cell.textLabel.text = @"CAPS";
            cell.detailTextLabel.text = @"www.capspayroll.com";
            break;
        case ActPaymentSelectionTypeCentreCasting:
            cell.textLabel.text = @"Central Casting";
            cell.detailTextLabel.text = @"www.centralcasting.org";
            break;
        case  ActPaymentSelectionTypeEntertainment:
            cell.textLabel.text = @"Entertainments";
            cell.detailTextLabel.text = @"www.entertainmentpartners.com";
            break;
            
        default:
            break;
    }
    [cell.detailTextLabel setBackgroundColor:[UIColor clearColor]];

    UIView *accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 45)];
    UIButton *button  = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 45, 45)];
    [button setImage:[UIImage imageNamed:@"payment_selection_icon"] forState:UIControlStateNormal];
    [accessoryView addSubview:button];
    [button release];
    cell.accessoryView = accessoryView;
    [accessoryView release];
    
    [view addSubview:cell];
    [cell release];
    return view;
}
- (void)viewDidUnload {
    [self setNavigationView:nil];
    [super viewDidUnload];
}
@end
